import React, { useState, useEffect, createRef } from 'react'
import styles from '../../style/childPublic/childPublic.module.less'
import conBack from '../../style/contentBack/contentBack.module.less'
import { htAfficheById } from '../../apis/policyInformation'
import { ExclamationCircleOutlined } from '@ant-design/icons';
import { Timeline, Button, Image, message, Input, Drawer, FloatButton, Modal } from 'antd';
import { useLocation } from 'react-router-dom';
import Editor from '../../components/EditorAirt/EditorAirt'
import HeaderTop from "../../components/HeaderTop/HeaderTop";
export default function OperatingDemonstration() {
  const { state } = useLocation();
  const [messageApi, contextHolder] = message.useMessage();
  const key = 'updatable';
  const [title] = useState('农药经营示范点信息发布管理')
  const [html, setHtml] = useState('')
  const keyWordsRef = createRef();
  const [keyWords, setKeyWords] = useState('')


  const [modal, contextHolder_] = Modal.useModal();
  const [htmContent, setHtmContent] = useState({})
  useEffect(() => {
    htAfficheByIdGet()
  }, []);

  // 取消
  const cancel = () => {
    console.log('fanhui ')
    //window.history.back();
  }
  const htAfficheByIdGet = async () => {
    const { data } = await htAfficheById({ id: state.newArry.id })
    if (data.state === 1) {
      setHtmContent(data.data.data)
      setHtml(data.data.info)
      setKeyWords(data.data.name)
    }
  }

  // 删除
  // const htDelete = async () => {

  // const { data } = await htAfficheDelete({ idArr: [oneId] })

  // if (data.state === 1) {
  //   messageApi.open({
  //     key,
  //     type: 'success',
  //     content: '删除成功',
  //     duration: 100,
  //   });
  //   setTimeout(function () {  //延迟
  //     setOpen(false);
  //     // pubLish()
  //   }, 2000)

  // } else {
  //   messageApi.open({
  //     key,
  //     type: 'error',
  //     content: data.msg,
  //     duration: 1000,
  //   });
  // }

  // }

  // const confirm = () => {
  //   modal.confirm({
  //     title: '注意',
  //     icon: <ExclamationCircleOutlined />,
  //     content: '确定要删除文章吗？',
  //     okText: '确认',
  //     cancelText: '取消',
  //     onOk() {
  //       htDelete()
  //     },
  //     onCancel() {

  //     }
  //   });
  // };
  return (
    <div div className={styles.pubBack}>
      {contextHolder}
      <HeaderTop title={title}></HeaderTop>
      <div className={conBack.contentBack}>
        <span className={conBack.topTitle}>信息发布管理列表</span>
        <div className={conBack.timeBox}>
          <div className={`${conBack.popBox} ${conBack.showBox}`}>
            <div className={conBack.inputK}>
              <Input placeholder="请输入文章标题" ref={keyWordsRef} value={keyWords} onChange={() => {
                setKeyWords(keyWordsRef.current.input.value)
              }} style={{ height: '5vh', overflowY: 'hidden', width: '90vw' }} />
            </div>
            <Editor html={html} setHtml={setHtml} keyWords={keyWords} dataItem={state.newArry} ></Editor>
            <div className={conBack.but}>
              <Button type="primary" onClick={() => cancel()}>取消</Button>
            </div>
          </div>
        </div>
        <>
          {contextHolder_}
        </>
      </div>
    </div>
  )
}
